package com.atguigu.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/send/")
public class ProductController {


    @Autowired
    private RabbitTemplate rabbitTemplate;//自动装配rabbitmq模板对象，通过它可以发消息到mq

    @GetMapping("{msg}")
    public String sendTest1Message(@PathVariable("msg") String msg) {
        System.out.println(msg);
        //发消息到消息队列
        //参数1:交换机名称 参数二：路由key 参数三：消息内容
        rabbitTemplate.convertAndSend("spring.test1.exchange", "a.b.c", msg);
        return "成功";
    }

    @GetMapping("test2/{msg}")
    public String sendTest2Message(@PathVariable("msg") String msg) {
        System.out.println(msg);
        //发消息到消息队列
        //参数1:交换机名称 参数二：路由key 参数三：消息内容
        rabbitTemplate.convertAndSend("test2_service_exchange", "test2.b", msg);
        return "成功";
    }


}
